home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / PHP / include / php / ext / standard / php_smart_str.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-26  |  2.8 KB  |  92 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | PHP version 4.0                                                      |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1997-2001 The PHP Group                                |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 2.02 of the PHP license,      |
  8.    | that is bundled with this package in the file LICENSE, and is        |
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.php.net/license/2_02.txt.                                 |
  11.    | If you did not receive a copy of the PHP license and are unable to   |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@php.net so we can mail you a copy immediately.               |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Sascha Schumann <sascha@schumann.cx>                        |
  16.    +----------------------------------------------------------------------+
  17.  */
  18.  
  19. #ifndef PHP_SMART_STR_H
  20. #define PHP_SMART_STR_H
  21.  
  22. #include "php_smart_str_public.h"
  23.  
  24. #include <stdlib.h>
  25. #include <zend.h>
  26.  
  27. #define smart_str_0(x) ((x)->c[(x)->len] = '\0')
  28.  
  29. #define smart_str_alloc(d,n,what) {\
  30.     if (!d->c) d->len = d->a = 0; \
  31.     newlen = d->len + n; \
  32.     if (newlen >= d->a) {\
  33.         d->c = perealloc(d->c, newlen + 129, what); \
  34.         d->a = newlen + 128; \
  35.     }\
  36. }
  37.  
  38. #define smart_str_appends_ex(dest, src, what) smart_str_appendl_ex(dest, src, strlen(src), what)
  39. #define smart_str_appends(dest, src) smart_str_appendl(dest, src, strlen(src))
  40.  
  41. #define smart_str_appendc(dest, c) smart_str_appendc_ex(dest, c, 0)
  42. #define smart_str_free(s) smart_str_free_ex(s, 0)
  43. #define smart_str_appendl(dest,src,len) smart_str_appendl_ex(dest,src,len,0)
  44. #define smart_str_append(dest, src) smart_str_append_ex(dest,src,0)
  45.  
  46. static inline void smart_str_appendc_ex(smart_str *dest, char c, int what)
  47. {
  48.     size_t newlen;
  49.  
  50.     smart_str_alloc(dest, 1, what);
  51.     dest->len = newlen;
  52.     dest->c[dest->len - 1] = c;
  53. }
  54.  
  55.  
  56. static inline void smart_str_free_ex(smart_str *s, int what)
  57. {
  58.     if (s->c) {
  59.         pefree(s->c, what);
  60.         s->c = NULL;
  61.     }
  62.     s->a = s->len = 0;
  63. }
  64.  
  65. static inline void smart_str_appendl_ex(smart_str *dest, const char *src, size_t len, int what)
  66. {
  67.     size_t newlen;
  68.  
  69.     smart_str_alloc(dest, len, what);
  70.     memcpy(dest->c + dest->len, src, len);
  71.     dest->len = newlen;
  72. }
  73.  
  74. static inline void smart_str_append_ex(smart_str *dest, smart_str *src, int what)
  75. {
  76.     smart_str_appendl_ex(dest, src->c, src->len, what);
  77. }
  78.  
  79. static inline void smart_str_setl(smart_str *dest, const char *src, size_t len)
  80. {
  81.     dest->len = len;
  82.     dest->a = len + 1;
  83.     dest->c = (char *) src;
  84. }
  85.  
  86. static inline void smart_str_sets(smart_str *dest, const char *src)
  87. {
  88.     smart_str_setl(dest, src, strlen(src));
  89. }
  90.  
  91. #endif
  92.